/*
 * @Author: sdorein sdorein@163.com
 * @Date: 2024-09-14 13:44:46
 * @LastEditors: sdorein sdorein@163.com
 * @LastEditTime: 2024-10-30 13:53:44
 * @FilePath: \Vue3-ts-vite-template\src\main.ts
 * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { createApp } from 'vue'
import './style.css'
import App from './App.vue'
import Sub from './Sub.vue'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import router from './router';
import subrouter from './router/sub'
import TestPlugin from './plugins/test'

import Footer from './components/Footer.vue'
// --双路由配置
const app = createApp(App)
const sub = createApp(Sub)
// --图片懒加载--vue 自定义指令
app.directive('lazy', {
  // 当被绑定的元素挂载到DOM上时...
  mounted(el, binding) {
    // 创建一个IntersectionObserver实例
    const observer = new IntersectionObserver((entries, observer) => {
      entries.forEach(entry => {
        if (entry.isIntersecting) {
          // 当元素进入视口时，设置图片的src属性
          el.src = binding.value;
          // 观察完这个元素后，停止观察
          observer.unobserve(el);
        }
      });
    });

    // 开始观察这个元素
    observer.observe(el);
  }
});
sub.directive('lazy', {
  // 当被绑定的元素挂载到DOM上时...
  mounted(el, binding) {
    // 创建一个IntersectionObserver实例
    const observer = new IntersectionObserver((entries, observer) => {
      entries.forEach(entry => {
        if (entry.isIntersecting) {
          // 当元素进入视口时，设置图片的src属性
          el.src = binding.value;
          // 观察完这个元素后，停止观察
          observer.unobserve(el);
        }
      });
    });

    // 开始观察这个元素
    observer.observe(el);
  }
});
app.component('Footer', Footer)
app.use(router);
app.use(TestPlugin, {})
app.use(ElementPlus)
sub.use(subrouter);
sub.use(ElementPlus);
app.mount('#app')
sub.mount('#sub')
